package com.dmgis.qxfw.dataservice.businessservice.yyjt.service.Impl;


import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.raidentemp;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.township_forecasttemp;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.ybzz_forecastfinal;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.job_model;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ActualElemQuery;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.TrafficSearch;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.yyjt.service.IForecastInfoService;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service("TraService")
public class ForecastInfoServiceImpl implements IForecastInfoService {
    private final String operatingSystem;

    @Autowired
    public ForecastInfoServiceImpl(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }

    @Resource
    private ITransformService transformService;

    HttpRequestUtil httpUtil = new HttpRequestUtil();
    ProcessRequestController process = new ProcessRequestController();

    //MongoService1 ms = new MongoService1();
    FileRequestService ms = new FileRequestService();

    @Override
    public TownshipForecastKey getTownNewDate() {
        // TODO 获取乡镇预报最新时间
        TownshipForecastKey newDate = new TownshipForecastKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%' ", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "township_forecast");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecastKey>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDateChar(DateTime.now().toDate());
            int time = DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? 8 : 20;
            String timechar = "";
            if (time < 10) {
                timechar = "08";
            }
            newDate.setTimeChar(timechar);
        }
        return newDate;
    }

    @Override
    public Traffic getTrafficNewDate() {
        // TODO 获取交通预报最新时间
        Traffic result = new Traffic();
        traffic newestDate = new traffic();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"announcedTime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"announcedTime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "traffic");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setAnnouncedtime(DateTime.now().toDate());
        }
        if (newestDate != null) {
            result.setAnnouncedTime(newestDate.getAnnouncedtime());
        }
        return result;
    }

    @Override
    public List<traffic> initshici(String announcedtime) {
        List<traffic> listData = new ArrayList<traffic>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("DISTINCT to_char(announcedtime,'HH') as sc");
        selectRequest.setSort(new String[]{"sc desc"});
        selectRequest.setParam("  forecasttype=1 and announcedtime=" + "'" + announcedtime + "'");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "traffic");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }


    @Override
    public List<Traffic> getTraffic(TrafficSearch trafficsearch) {
        // TODO 获取交通预报
        List<traffic_weather_sta> listData = new ArrayList<traffic_weather_sta>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        List<traffic> resultlistData = new ArrayList<traffic>();
        List<Traffic> finalresultList = new ArrayList<Traffic>();
        Map<String, String> selecttraParam = new HashMap<String, String>();
        RequestDataBySelect selecttraRequest = new RequestDataBySelect();

        List<String> columns = new ArrayList<String>();
        columns.add("stationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(trafficsearch.getTypes())) {
            strWhere.append(String.format(" and roadtype='%s'", trafficsearch.getTypes()));
        }
        if (!StringUtil.IsNullOrEmpty(trafficsearch.getStrstaName())) {
            strWhere.append(String.format(" and stationname='%s'", trafficsearch.getStrstaName()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "traffic_weather_sta");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_weather_sta>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (traffic_weather_sta trafficsta : listData) {
                Combatpoint combatpoint = new Combatpoint();
                combatpoint.setStationname(trafficsta.getStationname());
                List<String> columnstra = new ArrayList<String>();
                columnstra.add("trafficsid");
                columnstra.add("stationname");
                columnstra.add("longitude");
                columnstra.add("latitude");
                columnstra.add("forcastlevel");
                columnstra.add("viewlevel");
                columnstra.add("explain");
                columnstra.add("weather12");
                columnstra.add("maxtemp");
                columnstra.add("mintemp");
                columnstra.add("wind");
                columnstra.add("windd");
                columnstra.add("lmmaxtemp");
                columnstra.add("lmmintemp");
                columnstra.add("lmmcxs");
                columnstra.add("(cast(announcedtime as timestamp)+ cast(ntimes||'hour' as INTERVAL)) as announcedtime");
                columnstra.add("ntimes");
                selecttraRequest.setColumns(columnstra.toArray(new String[columnstra.size()]));
                // 拼接where字段
                StringBuilder strWheretra = new StringBuilder();
                int whereCounttra = 0;
                if (!StringUtil.IsNullOrEmpty(combatpoint.getStationname())) {
                    strWheretra.append(String.format(" and  stationname='%s'", combatpoint.getStationname()));//and
                }
                if (trafficsearch.getTime() != null) {
                    strWheretra.append(String.format(" and announcedTime='%s'", trafficsearch.getTime()));
                }
                if (!StringUtil.IsNullOrEmpty(trafficsearch.getForcastlevel())) {
                    strWheretra.append(String.format(" and forecasttype='%s'", trafficsearch.getForcastlevel()));
                }
                if (whereCounttra == 0 && !StringUtil.IsNullOrEmpty(strWheretra.toString())) {
                    strWheretra = strWheretra.replace(0, 4, "");
                }
                selecttraRequest.setParam(strWheretra.toString());
                selecttraRequest.setSort(new String[]{"(cast(announcedtime as timestamp)+ cast(ntimes||'hour' as INTERVAL)) asc"});
                try {
                    selecttraParam.put("method", "traffic");
                    selecttraParam.put("sqlType", "select");
                    selecttraParam.put("advCode", DbConfig.advCode);
                    selecttraParam.put("param", JsonUtil.object2Json(selecttraRequest));
                    String message = process.processRequest(selecttraParam);
                    resultlistData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
                    });
                } catch (Exception e) {
                    // TODO: handle exception
                }
                if (resultlistData != null && resultlistData.size() > 0) {
                    for (traffic traf : resultlistData) {
                        Traffic traffic = new Traffic();
                        traffic.setTrafficSID(traf.getTrafficsid());
                        traffic.setStationName(traf.getStationname());
                        traffic.setLon(traf.getLongitude());
                        traffic.setLat(traf.getLatitude());
                        traffic.setForcastLevel(traf.getForcastlevel());
                        traffic.setViewLevel(traf.getViewlevel());
                        traffic.setExplain(traf.getExplain());
                        traffic.setMaxTemp(traf.getMaxtemp());
                        traffic.setMinTemp(traf.getMintemp());
                        traffic.setWeather12(traf.getWeather12());
                        traffic.setWind(traf.getWind());
                        traffic.setWindD(traf.getWindd());
                        traffic.setLMMaxTemp(traf.getLmmaxtemp());
                        traffic.setLMMinTemp(traf.getLmmintemp());
                        traffic.setLMMCXS(traf.getLmmcxs());
                        traffic.setNtimes(traf.getNtimes());
                        traffic.setTime(new DateTime(traf.getAnnouncedtime()).toDateTimeString());
                        finalresultList.add(traffic);
                    }
                }

            }
        }
        return finalresultList;
    }

    @Override
    public List<Combatpoint> getCoordinate(TrafficSearch trafficsearch) {
        // TODO 路段坐标
        List<traffic_weather_sta> listData = new ArrayList<traffic_weather_sta>();
        List<Combatpoint> resultList = new ArrayList<Combatpoint>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("roadcoordinate");
        columns.add("roadtype");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(trafficsearch.getTypes())) {
            whereCount++;
            strWhere.append(String.format("roadtype='%s'", trafficsearch.getTypes()));
        }
        if (!StringUtil.IsNullOrEmpty(trafficsearch.getStrstaName())) {
            strWhere.append(String.format(" and stationname='%s'", trafficsearch.getStrstaName()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "traffic_weather_sta");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_weather_sta>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (traffic_weather_sta trafficsta : listData) {
                Combatpoint combatpoint = new Combatpoint();
                combatpoint.setStationname(trafficsta.getStationname());
                combatpoint.setStationid(trafficsta.getStationid());
                combatpoint.setRoadcoordinate(trafficsta.getRoadcoordinate());
                combatpoint.setRoadtype(trafficsta.getRoadtype());
                resultList.add(combatpoint);
            }
        }
        return resultList;
    }

    @Override
    public List<TownshipForecast> getHighway(TownshipForecastKey selectKey) {
        // TODO 高速公路信息
        List<traffic_hightway_pnt> listData = new ArrayList<traffic_hightway_pnt>();
        List<township_forecasttemp> listData1 = new ArrayList<township_forecasttemp>();
        float fx = 0;
        float fy = 0;
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("relfcststa");
        columns.add("fx");
        columns.add("fy");
        columns.add("stationname");
        columns.add("stationtype");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere1 = new StringBuilder();
        Integer whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationID())) {
            whereCount++;
            strWhere1.append(" relfcststa ='" + selectKey.getStationID() + "'");
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationName()) && !selectKey.getStationName().equals("全部")) {
            strWhere1.append(" and stationname ='" + selectKey.getStationName() + "'");
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere1.toString())) {
            strWhere1 = strWhere1.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere1.toString());
        try {
            selectParam.put("method", "traffic_hightway_pnt");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_hightway_pnt>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            String strStaID = "";
            for (traffic_hightway_pnt hightway : listData) {
                strStaID += "'" + hightway.getRelfcststa() + "',";
                fx = hightway.getFx();
                fy = hightway.getFy();
            }
            strStaID = strStaID.substring(0, strStaID.length() - 1);
            Map<String, String> selectParam1 = new HashMap<String, String>();
            RequestDataBySelect selectRequest1 = new RequestDataBySelect();
            List<String> columns1 = new ArrayList<String>();
            columns1.add("to_char(datechar,'yyyy-MM-dd HH24:MI:SS') as datechar");
            columns1.add("stationid");
            columns1.add("stationname");
            columns1.add("Weather1");
            columns1.add("longitude");
            columns1.add("latitude");
            columns1.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
            columns1.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
            columns1.add("winds");
            columns1.add("windd");
            selectRequest1.setColumns(columns1.toArray(new String[columns1.size()]));
            // 拼接where字段
            StringBuilder strWhere = new StringBuilder();
            if (selectKey.getDateChar() != null) {
                strWhere.append(String.format(" datechar='%tF'", selectKey.getDateChar()));
            }
            if (!StringUtil.IsNullOrEmpty(selectKey.getTimeChar())) {
                strWhere.append(String.format(" and timechar='%s'", selectKey.getTimeChar()));
            }
            if (selectKey.getNTimes() != null && selectKey.getNTimes() > 0) {
                strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", selectKey.getNTimes(),
                        selectKey.getNTimes() - 24));
            }
            if (!StringUtil.IsNullOrEmpty(strStaID)) {
                strWhere.append(String.format(" and stationid in (" + strStaID + ")"));
            }
            strWhere.append(String.format("and areaname like '%s%%'", DbConfig.COUNTY));
            selectRequest1.setParam(strWhere.toString());
            selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
            try {
                if (DateTime.UserMainDataTable(selectKey.getDateChar(), DbConfig.CACHEDAYS)) {
                    selectParam1.put("method", "township_forecast");
                } else {
                    selectParam1.put("method", "township_forecast");
                }
                selectParam1.put("sqlType", "select");
                selectParam1.put("param", JsonUtil.object2Json(selectRequest1));
                String message1 = process.processRequest(selectParam1);
                listData1 = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<township_forecasttemp>>() {
                });
            } catch (Exception e) {
                // TODO: handle exception
            }
            if (listData1 != null && listData1.size() > 0) {
                for (traffic_hightway_pnt hightway : listData) {
                    for (township_forecasttemp fcst : listData1) {
                        TownshipForecast word = new TownshipForecast();
                        if (hightway.getRelfcststa().contains(fcst.getStationid())) {
                            word.setLongitude(fcst.getLongitude());
                            word.setLatitude(fcst.getLatitude());
                            word.setStationName(hightway.getStationname());
                            word.setStationtype(hightway.getStationtype());
                            word.setStationID(fcst.getStationid());
                            word.setWeather1(fcst.getWeather1());
                            word.setMaxTemp(fcst.getMaxtemp());
                            word.setMinTemp(fcst.getMintemp());
                            word.setWindS(fcst.getWinds());
                            word.setWindD(fcst.getWindd());
                            word.setDateChar(fcst.getDatechar());
                            resultList.add(word);
                        }
                    }
                }
            }
        }
        return resultList;
    }

    @Override
    public List<TrafficWord> getTrafficDoc(TrafficSearch trafficsearch) {
        // TODO 交通预报文档
        List<base_product> listData = new ArrayList<base_product>();
        List<TrafficWord> resultList = new ArrayList<TrafficWord>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("productname");
        columns.add("producttype");
        columns.add("forecasttime");
        columns.add("maker");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (trafficsearch.getTime() != null) {
            strWhere.append(String.format(" and forecasttime='%s'", trafficsearch.getTime()));
        }
        if (StringUtil.IsNullOrEmpty(trafficsearch.getTypes())) {
            strWhere.append(String.format(" and producttype='%s'", "交通预报"));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (base_product product : listData) {
                TrafficWord word = new TrafficWord();
                word.setId(product.getId());
                word.setForecasttime(product.getForecasttime());
                word.setProductname(product.getProductname());
                word.setProducttype(product.getProducttype());
                resultList.add(word);
            }
        }
        return resultList;
    }

    @Override
    public List<traffic_hightway_pnt> getHightwaypnt() {
        // TODO 高速公路站点
        List<traffic_hightway_pnt> listData = new ArrayList<traffic_hightway_pnt>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "traffic_hightway_pnt");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_hightway_pnt>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.getStackTrace();
        }
        return listData;
    }

    @Override
    public Traffic getNewDate() {
        Traffic result = new Traffic();
        traffic newestDate = new traffic();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"announcedTime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"announcedTime desc"});
        selectRequest.setParam("forecasttype = '1'");
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "traffic");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setAnnouncedtime(DateTime.now().toDate());
        }
        if (newestDate != null) {
            result.setAnnouncedTime(newestDate.getAnnouncedtime());
        }
        return result;
    }

    @Override
    public List<ybzz_forecastfinal> getDayHighway(TownshipForecastKey selectKey) {
        List<traffic_hightway_pnt> listData = new ArrayList<traffic_hightway_pnt>();
        List<ybzz_forecastfinal> listData1 = new ArrayList<ybzz_forecastfinal>();
        float fx = 0;
        float fy = 0;
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("relfcststa");
        columns.add("fx");
        columns.add("fy");
        columns.add("stationname");
        columns.add("stationtype");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere1 = new StringBuilder();
        Integer whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationID())) {
            whereCount++;
            strWhere1.append(" relfcststa ='" + selectKey.getStationID() + "'");
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationName()) && !selectKey.getStationName().equals("全部")) {
            strWhere1.append(" and stationname ='" + selectKey.getStationName() + "'");
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere1.toString())) {
            strWhere1 = strWhere1.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere1.toString());
        try {
            selectParam.put("method", "traffic_hightway_pnt");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_hightway_pnt>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            String strStaID = "";
            for (traffic_hightway_pnt hightway : listData) {
                strStaID += "'" + hightway.getRelfcststa() + "',";
                fx = hightway.getFx();
                fy = hightway.getFy();
            }
            strStaID = strStaID.substring(0, strStaID.length() - 1);
            Map<String, String> selectParam1 = new HashMap<String, String>();
            RequestDataBySelect selectRequest1 = new RequestDataBySelect();
            List<String> columns1 = new ArrayList<String>();
            columns1.add("to_char(cast(datechar as timestamp)+ cast((ntimes)||'hour' as INTERVAL),'yyyy-MM-dd HH24:MI:SS') as datechar");
            columns1.add("stationid");
            columns1.add("weather");
            columns1.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
            columns1.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as mintemp");
            columns1.add("wind");
            columns1.add("windd");
            selectRequest1.setColumns(columns1.toArray(new String[columns1.size()]));
            // 拼接where字段
            StringBuilder strWhere = new StringBuilder();
            if (selectKey.getDateChar() != null && !StringUtil.IsNullOrEmpty(selectKey.getTimeChar())) {
                strWhere.append(String.format("to_char(cast(datechar as timestamp)+ cast((ntimes)||'hour' as INTERVAL),'yyyy-MM-dd HH24:MI:SS')>='%s'", new DateTime(selectKey.getDateChar()).AddHours(Integer.parseInt(selectKey.getTimeChar())).toDateTimeString()));
                strWhere.append(String.format(" and to_char(cast(datechar as timestamp)+ cast((ntimes)||'hour' as INTERVAL),'yyyy-MM-dd HH24:MI:SS')<='%s'", new DateTime(selectKey.getDateChar()).AddDays(1).AddHours(Integer.parseInt(selectKey.getTimeChar())).toDateTimeString()));
            }
            if (selectKey.getNTimes() != null && selectKey.getNTimes() > 0) {
                strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", selectKey.getNTimes(),
                        selectKey.getNTimes() - 24));
            }
            if (!StringUtil.IsNullOrEmpty(strStaID)) {
                strWhere.append(String.format(" and stationid in (" + strStaID + ")"));
            }
            strWhere.append(String.format(" and forecasttype='1'"));
            selectRequest1.setParam(strWhere.toString());
            selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
            try {
                selectParam1.put("method", "ybzz_forecastfinal");
                selectParam1.put("sqlType", "select");
                selectParam1.put("param", JsonUtil.object2Json(selectRequest1));
                String message1 = process.processRequest(selectParam1);
                listData1 = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<ybzz_forecastfinal>>() {
                });
                if (listData1 != null && listData1.size() > 0) {
                    for (ybzz_forecastfinal ybzz : listData1) {
                        ybzz.setUsername(listData.get(0).getStationname());
                        ybzz.setWeather12(new DateTime(ybzz.getDatechar()).toDateTimeString());
                        ybzz.setLon(fx);
                        ybzz.setLat(fy);
                    }
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
        return listData1;
    }

    @Override
    public List<Traffic> getJXHTraffic(String startDate, String endDate, String types, String forcastlevel) {
        List<traffic_weather_sta> listData = new ArrayList<traffic_weather_sta>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        List<traffic> resultlistData = new ArrayList<traffic>();
        List<Traffic> finalresultList = new ArrayList<Traffic>();
        Map<String, String> selecttraParam = new HashMap<String, String>();
        RequestDataBySelect selecttraRequest = new RequestDataBySelect();

        List<String> columns = new ArrayList<String>();
        columns.add("stationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(types)) {
            strWhere.append(String.format(" and roadtype='%s'", types));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "traffic_weather_sta");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_weather_sta>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (traffic_weather_sta trafficsta : listData) {
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                selecttraParam = new HashMap<String, String>();
                selecttraRequest = new RequestDataBySelect();
                columns = new ArrayList<String>();
                columns.add("max(announcedtime) as announcedtime");
                selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                // 拼接where字段
                strWhere = new StringBuilder();
                if (!StringUtil.IsNullOrEmpty(trafficsta.getStationname())) {
                    strWhere.append(String.format(" and stationname='%s'", trafficsta.getStationname()));
                }
                if (!StringUtil.IsNullOrEmpty(forcastlevel)) {
                    strWhere.append(String.format(" and forecasttype='%s'", forcastlevel));
                }
                if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                    strWhere = strWhere.replace(0, 4, "");
                }
                selectRequest.setParam(strWhere.toString());
                List<traffic> trafficList = new ArrayList<traffic>();
                try {
                    selectParam.put("method", "traffic");
                    selectParam.put("sqlType", "select");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String message = process.processRequest(selectParam);
                    trafficList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
                    });
                } catch (Exception e) {
                    // TODO: handle exception
                }
                if (trafficList != null && trafficList.size() > 0) {

                    Combatpoint combatpoint = new Combatpoint();
                    combatpoint.setStationname(trafficsta.getStationname());
                    List<String> columnstra = new ArrayList<String>();
                    columnstra.add("trafficsid");
                    columnstra.add("stationname");
                    columnstra.add("longitude");
                    columnstra.add("latitude");
                    columnstra.add("forcastlevel");
                    columnstra.add("viewlevel");
                    columnstra.add("explain");
                    columnstra.add("weather12");
                    columnstra.add("maxtemp");
                    columnstra.add("mintemp");
                    columnstra.add("wind");
                    columnstra.add("windd");
                    columnstra.add("lmmaxtemp");
                    columnstra.add("lmmintemp");
                    columnstra.add("lmmcxs");
                    columnstra.add("(cast(announcedtime as timestamp)+ cast(ntimes||'hour' as INTERVAL)) as announcedtime");
                    columnstra.add("ntimes");
                    selecttraRequest.setColumns(columnstra.toArray(new String[columnstra.size()]));
                    // 拼接where字段
                    StringBuilder strWheretra = new StringBuilder();
                    int whereCounttra = 0;
                    if (!StringUtil.IsNullOrEmpty(combatpoint.getStationname())) {
                        strWheretra.append(String.format(" and stationname='%s'", combatpoint.getStationname()));
                    }
                    if (!StringUtil.IsNullOrEmpty(startDate)) {
                        strWheretra.append(String.format(" and (cast(announcedtime as timestamp)+ cast((cast(ntimes as integer))||'hour' as INTERVAL))>='%s'", startDate));
                    }
                    if (!StringUtil.IsNullOrEmpty(endDate)) {
                        strWheretra.append(String.format(" and (cast(announcedtime as timestamp)+ cast((cast(ntimes as integer))||'hour' as INTERVAL))<='%s'", endDate));
                    }
                    if (!StringUtil.IsNullOrEmpty(forcastlevel)) {
                        strWheretra.append(String.format(" and forecasttype='%s'", forcastlevel));
                    }
                    if (trafficList.get(0).getAnnouncedtime() != null) {
                        strWheretra.append(String.format(" and announcedtime='%s'", trafficList.get(0).getAnnouncedtime()));
                    }
                    if (whereCounttra == 0 && !StringUtil.IsNullOrEmpty(strWheretra.toString())) {
                        strWheretra = strWheretra.replace(0, 4, "");
                    }
                    selecttraRequest.setParam(strWheretra.toString());
                    selecttraRequest.setSort(new String[]{"(cast(announcedtime as timestamp)+ cast(ntimes||'hour' as INTERVAL)) asc"});
                    try {
                        selecttraParam.put("method", "traffic");
                        selecttraParam.put("sqlType", "select");
                        selecttraParam.put("advCode", DbConfig.advCode);
                        selecttraParam.put("param", JsonUtil.object2Json(selecttraRequest));
                        String message = process.processRequest(selecttraParam);
                        resultlistData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
                        });
                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }
                if (resultlistData != null && resultlistData.size() > 0) {
                    for (traffic traf : resultlistData) {
                        Traffic traffic = new Traffic();
                        traffic.setTrafficSID(traf.getTrafficsid());
                        traffic.setStationName(traf.getStationname());
                        traffic.setLon(traf.getLongitude());
                        traffic.setLat(traf.getLatitude());
                        traffic.setForcastLevel(traf.getForcastlevel());
                        traffic.setViewLevel(traf.getViewlevel());
                        traffic.setExplain(traf.getExplain());
                        traffic.setMaxTemp(traf.getMaxtemp());
                        traffic.setMinTemp(traf.getMintemp());
                        traffic.setWeather12(traf.getWeather12());
                        traffic.setWind(traf.getWind());
                        traffic.setWindD(traf.getWindd());
                        traffic.setLMMaxTemp(traf.getLmmaxtemp());
                        traffic.setLMMinTemp(traf.getLmmintemp());
                        traffic.setLMMCXS(traf.getLmmcxs());
                        traffic.setNtimes(traf.getNtimes());
                        traffic.setTime(new DateTime(traf.getAnnouncedtime()).toDateTimeString());
                        finalresultList.add(traffic);
                    }
                }

            }
        }
        return finalresultList;
    }

    @Override
    public List<traffic_weather_sta> initJXHTraffic(String types) {
        List<traffic_weather_sta> listData = new ArrayList<traffic_weather_sta>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("distinct stationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (!StringUtil.IsNullOrEmpty(types)) {
            selectRequest.setParam("roadtype = '" + types + "'");
        }
        try {
            selectParam.put("method", "traffic_weather_sta");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic_weather_sta>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }


    /**
     * 初始化常规产品
     *
     * @param types
     * @return
     */
    @Override
    public List<job_model> initWordPage(String types) {
        List<job_model> listData = new ArrayList<job_model>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("distinct twotype");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (!StringUtil.IsNullOrEmpty(types)) {
            selectRequest.setParam("onetype = '" + types + "'");
        }
        try {
            selectParam.put("method", "job_model");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<job_model>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<summary_product> getCommonWord(String bigtype, String smalltype, HttpServletRequest request) {
        List<summary_product> listData = new ArrayList<summary_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("forecasttime");
        columns.add("productname");
        columns.add("maketime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" status='1' ");
        int whereCount = 0;
        if (bigtype.equals("环境气象公报")) {
            bigtype = "环境气象服务";
            smalltype = "环境气象公报";
        }
        if (bigtype.equals("环境气象趋势分析")) {
            bigtype = "环境气象服务";
            smalltype = "环境气象趋势分析";
        }
        if (bigtype.equals("环境气象服务专题")) {
            bigtype = "环境气象服务";
            smalltype = "环境气象服务专题";
        }
        if (!StringUtil.IsNullOrEmpty(bigtype)) {
            whereCount++;
            strWhere.append(String.format(" and  producttype='%s'", bigtype));
        }

        if (!StringUtil.IsNullOrEmpty(smalltype)) {
            strWhere.append(String.format(" and producttype2='%s'", smalltype));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"maketime desc "});
        selectRequest.setLimit(5);
        try {
            selectParam.put("method", "summary_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<summary_product>>() {
            });

            for (summary_product product : listData) {
                String serviceFilePath = "";
                // 下载
                String fileName = product.getProductname();
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/product/";
                String serviceUrl = basePath + fileName;

                String urlpath;
                if (operatingSystem.equals("Windows")) {
                    urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                } else {
                    urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/product/";
                }

                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                // 如果目录中不存在文件，下载雷达文件到temp目录
                File serviceFile = new File(serviceFilePath);// 服务器文件
                if (!serviceFile.exists()) {// 把文件上传到服务器
                    Map<String, Object> queryMap = new HashMap<String, Object>();
                    queryMap.put("id", product.getId() + "");
                    queryMap.put("table_name", "summary_product");
                    queryMap.put("advCode", DbConfig.advCode);
                    queryMap.put("collectionName", "pdf_file");
                    byte[] data = ms.selectData(queryMap);
                    if (data == null) {
                        serviceFilePath = "";
                    } else {
                        FileUtil.bytesToFile(data, serviceFilePath);
                    }
                }
                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String file = serviceFilePath;
                //添加路径
                product.setFilepath(file);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<summary_product> getSYCommonWord(String bigtype, String smalltype) {
        List<summary_product> listData = new ArrayList<summary_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("forecasttime");
        columns.add("productname");
        columns.add("producttype");
        columns.add("producttype2");
        columns.add("maketime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append("and status='1' ");
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(bigtype)) {
            whereCount++;
            String[] producttypes = bigtype.split(",");
            strWhere.append(" and producttype in (");
            String tempString = "'";
            for (int i = 0; i < producttypes.length; i++) {
                tempString += producttypes[i] + "','";
            }
            if (tempString.endsWith(",'")) {
                strWhere.append(tempString.substring(0, tempString.length() - 2) + ")");
            }
        }
        if (!StringUtil.IsNullOrEmpty(smalltype)) {
            strWhere.append(String.format(" and producttype2 in ('%s')", smalltype.replace(",", "','")));
        }
        if (whereCount != 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"maketime desc "});
        try {
            selectParam.put("method", "summary_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<summary_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }


    @Override
    public raidentemp initDate() {
        RequestDataBySelect query = new RequestDataBySelect();
        raidentemp r = new raidentemp();
        String[] columns = {"observetime"};
        query.setColumns(columns);
        query.setLimit(1);
        query.setParam(String.format(" city like '%s%%'", DbConfig.CITY));
        String[] sort = {"observetime desc"};
        query.setSort(sort);
        Map<String, String> paraMap = new HashMap<String, String>();
        try {
            paraMap.put("method", "raiden");
            paraMap.put("sqlType", "select");
            paraMap.put("param", JsonUtil.object2Json(query));
            String message = process.processRequest(paraMap);
            r = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raidentemp>>() {
            }).get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return r;
    }


    @Override
    public List<raidentemp> initContry() {
        List<raidentemp> rList = new ArrayList<raidentemp>();
        RequestDataBySelect query = new RequestDataBySelect();
        String[] columns = {"distinct county"};
        query.setParam(String.format(" city like '%s%%'", DbConfig.CITY));
        query.setColumns(columns);
        Map<String, String> paraMap = new HashMap<String, String>();
        try {
            paraMap.put("method", "raiden");
            paraMap.put("sqlType", "select");
            paraMap.put("param", JsonUtil.object2Json(query));
            String message = process.processRequest(paraMap);
            rList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raidentemp>>() {
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return rList;
    }

    @Override
    public List<raidentemp> getLeidian(String start, String end, String stationName, String ldPagingstart, String ldPaginglimit) {
        List<raidentemp> rList = new ArrayList<raidentemp>();
        RequestDataBySelect query = new RequestDataBySelect();
        String[] columns = {"observetime", "Lon", "Lat", "Strength", "Steepness", "Error"};
        query.setColumns(columns);

        /*if ("全部".equals(stationName)) {
            query.setParam("observetime between '" + start + "' and '" + end + "' and  city like '" + DbConfig.CITY + "%'");
        } else {
            query.setParam("observetime between '" + start + "' and '" + end + "' and County like '%%" + stationName + "%%'" + " and  city like '" + DbConfig.CITY + "%'");
        }*/
        query.setParam("observetime between '" + start + "' and '" + end+ "' and County like '%%" + "凌云" + "%%'");
        Map<String, String> paraMap = new HashMap<String, String>();
        try {
            paraMap.put("method", "raiden");
            paraMap.put("sqlType", "select");
            paraMap.put("param", JsonUtil.object2Json(query));
            String message = process.processRequest(paraMap);
            rList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raidentemp>>() {
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return rList;
    }


    @Override
    public List<base_product> getServiceDoc(String type, String kssj, String jssj) {
        List<base_product> mlist = new ArrayList<base_product>();
        try {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DAY_OF_MONTH, 1);
            String start = kssj;
            String end = jssj;

            RequestDataBySelect query = new RequestDataBySelect();
            String[] columns = {"id", "ProductName", "ProductType"};
            query.setColumns(columns);
            query.setParam("ProductType='" + type + "' and ForecastTime between '" + start + "' and '" + end + " 23:00:00'");

            Map<String, String> paraMap = new HashMap<String, String>();
            paraMap.put("method", "base_product");
            paraMap.put("sqlType", "select");
            paraMap.put("advCode", DbConfig.advCode);
            paraMap.put("param", JsonUtil.object2Json(query));
            String message = process.processRequest(paraMap);
            mlist = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mlist;
    }

    @Override
    public List<ActualData> qxWaringElementQuery(ActualElemQuery elemQuery) {
        // TODO 气象要素统计
        List<ActualData> resultList = new ArrayList<>();
        List<com.dmgis.qxfw.dataservice.businessservice.common.domain.MsgMediumSmallScale> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" city like '%s%%'", DbConfig.CITY));
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" and observTime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        if (countys != null && countys.size() > 0) {
            strWhere.append(" and county in (");
            String tempString = "";
            for (String county : countys) {
                tempString += String.format("'%s',", county);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        if (element != null && element.equals("rain")) {
            // 雨量和统计
            if (type != null) {
                columns.add("sum(rain) as rain");
                selectRequest.setSort(new String[]{"rain desc"});
                strWhere.append(" and rain <> -65535");
            }

        }
        if (element != null && element.equals("temp")) {
            // 温度统计
            if (type != null) {
                columns.add("cast(" + "avg" + "(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
                strWhere.append(" and DryBulbTemp <> -65535");
                selectRequest.setSort(new String[]{"DryBulbTemp desc"});
            }
        }
        if (element != null && element.equals("wind")) {
            // 风速统计
            if (type != null) {
                columns.add("avg" + "(InstantWindV) as InstantWindV");
                columns.add("instantwindd");
                strWhere.append(" and InstantWindV <> -65535");
                strWhere.append(" and instantwindd <> -65535");
                selectRequest.setSort(new String[]{"InstantWindV desc"});
            }
        }
        if (element != null && element.equals("humid")) {
            // 湿度统计
            if (type != null) {
                columns.add("cast(" + "avg" + "(RelHumidity) as integer) as RelHumidity");
                strWhere.append(" and RelHumidity <> -65535");
                selectRequest.setSort(new String[]{"RelHumidity desc"});
            }
        }
        if (element != null && element.equals("pressure")) {
            // 气压统计
            if (type != null) {
                columns.add("avg" + "(StationPress) as StationPress");
                strWhere.append(" and StationPress <> -65535");
                selectRequest.setSort(new String[]{"StationPress desc"});
            }
        }
        if (element != null && element.equals("visibility")) {
            // 能见度统计
            if (type != null) {
                columns.add("avg" + "(visibility) as visibility");
                strWhere.append(" and visibility <> -65535");
                selectRequest.setSort(new String[]{"visibility asc"});
            }
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = process.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<com.dmgis.qxfw.dataservice.businessservice.common.domain.MsgMediumSmallScale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        try {
            WebCtrlData webCtrlData = new WebCtrlData();
            if (dataList.size() > 0) {
                for (com.dmgis.qxfw.dataservice.businessservice.common.domain.MsgMediumSmallScale data : dataList) {
                    ActualData actualData = new ActualData();
                    actualData.setStationId(data.getStationid().trim());
                    actualData.setStationName(data.getStationname().trim());
                    actualData.setLon(data.getLongitude());
                    actualData.setLat(data.getLatitude());
                    DmMapPoint dt = transformService.LonLatConvertToLambert(data.getLongitude(), data.getLatitude());
                    actualData.setX(dt.x);
                    actualData.setY(dt.y);
                    switch (element) {
                        case "rain":
                            actualData.setRain(Double.parseDouble(String.format("%.1f", data.getRain())));
                            break;
                        case "temp":
                            actualData.setTemp(Double.parseDouble(String.format("%.1f", data.getDrybulbtemp())));
                            break;
                        case "humid":
                            actualData.setHumid(Double.parseDouble(String.format("%d", data.getRelhumidity())));
                            break;
                        case "wind":
                            actualData.setWinds(Double.parseDouble(String.format("%.1f", data.getInstantwindv())));
                            if (type != null) {
                                String s = webCtrlData.GetAllFx(data.getInstantwindd().toString());
                                actualData.setWinddirect(s);
                                int i = webCtrlData.FengSuToFengJi(data.getInstantwindv());
                                actualData.setWindvelocity(i);
                            }
                            break;
                        case "pressure":
                            actualData.setPressure(Double.parseDouble(String.format("%.1f", data.getStationpress())));
                            break;
                        case "visibility":
                            actualData.setVisibility(data.getVisibility());
                            break;
                        default:
                            break;
                    }
                    if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        actualData.setDateTime(sdf.parse(data.getDatechar()));
                    } else {
                        actualData.setDateTime(data.getObservtime());
                    }
                    resultList.add(actualData);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<job_model> getCommonWordType() {
        RequestDataBySelect query = new RequestDataBySelect();
        List<job_model> resultList = new ArrayList<>();
        List<String> colums = new ArrayList<>();
        colums.add("onetype");
        colums.add("twotype");
        query.setColumns(colums.toArray(new String[colums.size()]));
        HashMap<String, String> map = new HashMap<>();
        try {
            map.put("method", "job_model");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            map.put("param", JsonUtil.object2Json(query));
            String result = process.processRequest(map);
            resultList = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<job_model>>() {});

            // Step 1: 将数据按 onetype 分组
            Map<String, List<job_model>> groupedByOnetype = resultList.stream()
                    .collect(Collectors.groupingBy(job -> job.getOnetype()));

            // Step 2: 对于每个 onetype，合并 twotype 字段
            List<job_model> mergedResult = new ArrayList<>();
            for (Map.Entry<String, List<job_model>> entry : groupedByOnetype.entrySet()) {
                String onetype = entry.getKey();
                List<job_model> jobs = entry.getValue();

                // 合并所有 twotype 字段
                String mergedTwotype = jobs.stream()
                        .map(job -> job.getTwotype()) // 获取每个 job 的 twotype 字段
                        .filter(Objects::nonNull)      // 过滤掉 null 值
                        .collect(Collectors.joining("，")); // 合并成一个字符串，用中文逗号分隔

                // 创建新的 job_model 对象，并将合并后的 twotype 设置进去
                job_model mergedJob = new job_model();
                mergedJob.setOnetype(onetype);
                mergedJob.setTwotype(mergedTwotype);
                mergedJob.setModelname(null); // 保持 modelname 为 null
                mergedResult.add(mergedJob);
            }

            // Step 3: 更新 resultList 为合并后的结果
            resultList = mergedResult;

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return resultList;
    }
}
